package net.fkrahe.graph;

/**
 * Class WArcNode (Weightted ArcNode)
 * 
 * @author Yedidyah Langsan | Moshe Augenstein | Aaron M. Tenenbaum
 */
public class WArcNode extends ArcNode {

    private String weight;

//    public WArcNode() {
//        this(null, "");
//    }
//
//    public WArcNode(String weight) {
//        this(null, weight);
//    }

    public WArcNode(GraphNode ptr, String weight) {
        super(ptr);
        this.weight = weight;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String w) {
        weight = w;
    }

    @Override
    public String toString() {
        if (ptr != null) {
            if ("".equals(weight)) {
                return "-------> " + ptr.getInfo().toString();
            } else {
                return "--[" + weight + "]--> " + ptr.getInfo().toString();
            }
        } else {
            return weight + ";";
        }
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof WArcNode)) {
            return false;
        }
        WArcNode tmp = (WArcNode) o;

        boolean ptrComp;
        boolean weightComp;
        ptrComp = this.ptr == tmp.ptr ? true : false;

        if (getWeight() == null && tmp.getWeight() == null) {
            weightComp = true;
        } else if (getWeight() == null || tmp.getWeight() == null) {
            weightComp = false;
        } else {
            weightComp = this.getWeight().equals(tmp.getWeight()) ? true : false;
        }
        return (ptrComp && weightComp);
    }
}
